lexer grammar AnalexCLexer;

options {
  language = Java;
}

@lexer::header {
  package Practica8.Sintactico;
}

@lexer::members {
  private ArrayList<String> errors = new ArrayList<String>();
  public void displayRecognitionError(String[] tokenNames, RecognitionException e) {
    String hdr = getErrorHeader(e);
    String msg = getErrorMessage(e, tokenNames);
    errors.add(hdr + " " + msg);
  }
   
  public ArrayList<String> getErrors() {
    return errors;
  }
}

fragment SALTO_LINEA:  ('\r' '\n' | '\r' | '\n');
fragment DIGITO: '0'..'9';
fragment LETRA: 'A'..'Z' | 'a'..'z' | '_';
fragment OP_MAI: '>=';
fragment OP_MA: '>';
fragment OP_MEI: '<=';
fragment OP_ME: '<'; 
fragment OP_IIGUAL: '==';
fragment OP_DISTINTO: '!=';
fragment OP_AND: '&&';
fragment OP_OR: '||';

DATO_TIPO 
    :   'boolean'
    |   'char'
    |   'byte'
    |   'short'
    |   'int'
    |   'long'
    |   'float'
    |   'double'
    ;

 
KEYWORD_VOID
  : 'void'
  ;
  
KEYWORD_IF
  : 'if'
  ;
  
KEYWORD_WHILE
: 'while'
;
  
KEYWORD_FOR
: 'for'
;
  
KEYWORD_RETURN
  : 'return'
  ;
  
KEYWORD_INCLUDE
  : 'include'
  ; 
  
KEYWORD_BREAK
  : 'break'
  ;

COMENTARIO_LINEA: '//' (options { greedy=false;}:.)* SALTO_LINEA {skip();};
COMENTARIO_BLOQUE: '/*' ( options {greedy=false;} : . )* '*/' {skip();};
BLANCO: (' ' | '\t' | SALTO_LINEA) {skip();};
NUMERO: (OP_SUB)? (DIGITO)+('.'(DIGITO)+)?;
ID: LETRA (LETRA | DIGITO)*; 
CARACTER: '\'' (LETRA | DIGITO) '\'';
STRING: '\"' (options { greedy=false; }:.)* '\"';
CMP_SYMBOL: (OP_MA|OP_ME|OP_MAI|OP_MEI|OP_IIGUAL|OP_DISTINTO);
LOGIC_SYMBOL: (OP_AND|OP_OR);

OP_ASSIGN: '=';  
OP_COLON: ':';
OP_SUM: '+';
OP_SUB: '-';
OP_DIV: '/';
OP_MULT: '*';
OP_INC: '++';
OP_DEC: '--';
AMPERSAND: '&';
PIPE: '|';
LEFT_BRACE: '{'; 
RIGHT_BRACE: '}';
LEFT_PAREN: '(';
RIGHT_PAREN: ')';
LEFT_BRACKET: '[';
RIGHT_BRACKET: ']';
COMA: ',';
SEPARADOR: ';';
PERCENTAJE: '%';
CARET: '^';
QUESTIONMARK: '?';
OP_EXCLA: '!';
ALMOHADILLA: '#';